;
(function () {
    setTimeout(function () {
        var list = document.querySelectorAll('.item-img > a');
        var data = [];
        for (var i = 0; i < list.length; i++) {
            var href = list[i].getAttribute('href').match(/\d+/)[0];
            if (href) {
                data.push(href);
            }
        }
        //如果购物车内有商品
        if (data.length) {
            // 定义变量
            var append = '';
            // var baseUrl = 'https://apit.familyweb.cn/';
            var baseUrl = 'https://apiv2.sqyhq.cn/';
            var bg = baseUrl + 'gwc/click-bg1.png';
            var quan = baseUrl + 'gwc/quan.png';
            var shou = baseUrl + 'gwc/shou.png';
            var shouzhi = baseUrl + 'gwc/shouzhi.gif';
            //定义点击函数
            window.by_click = function () {
                // location.href = 'http://test.apiv2.sqyhq.cn/h5/gwc/index1.html?items=' + data.join(',');
                location.href = 'http://apiv2.sqyhq.cn/h5/gwc/index1.html?items=' + data.join(',');
            }
            //获取设备缩放比例
            var metas = document.querySelectorAll('meta');
            var type = 0;
            metas.forEach(function (v) {
                if (v.getAttribute('name') == 'viewport') {
                    if (v.getAttribute('content').indexOf('initial-scale=1') > -1) {
                        type = 1;
                    } else if (v.getAttribute('content').indexOf('initial-scale=0.5') > -1) {
                        type = 2;
                    } else if (v.getAttribute('content').indexOf('initial-scale=0.33') > -1) {
                        type = 3;
                    }
                }
            });
            // 构建插入元素
            if (type == 1) {
                append += '<div onclick="by_click()" style="position:fixed;z-index:9999;bottom:100px;left:0;right:0;display:flex;flex-direction:row;justify-content:center"><div style="position:relative">';
                append += '<div style="width:268px;height:60px;background-image:url(\'' + bg + '\');background-repeat:no-repeat;background-size:100% 100%;display:flex;flex-direction:row;justify-content:center;align-items:center"></div>';
                append += '<div style="position:absolute;top:10px;right:-10px;"><img src="' + shou + '" style="width:60px;height:60px"/></div>';
                append += '</div></div>';
            } else if (type == 2) {
                append += '<div onclick="by_click()" style="position:fixed;z-index:9999;bottom:200px;left:0;right:0;display:flex;flex-direction:row;justify-content:center"><div style="position:relative">';
                append += '<div style="width:536px;height:120px;background-image:url(\'' + bg + '\');background-repeat:no-repeat;background-size:100% 100%;display:flex;flex-direction:row;justify-content:center;align-items:center"></div>';
                append += '<div style="position:absolute;top:20px;right:-20px;"><img src="' + shou + '" style="width:120px;height:120px"/></div>';
                // append += '<div style="position:absolute;bottom:-20px;right:80px;"><img src="'+shou+'" style="width:120px;height:120px"/></div>';               
                append += '</div></div>';
            } else if (type == 3) {
                append += '<div onclick="by_click()" style="position:fixed;z-index:9999;bottom:300px;left:0;right:0;display:flex;flex-direction:row;justify-content:center"> <div style="position:relative">';
                append += '<div style="width:804px;height:180px;background-image:url(\'' + bg + '\');background-repeat:no-repeat;background-size:100% 100%;display:flex;flex-direction:row;justify-content:center;align-items:center"></div>';
                append += '<div style="position:absolute;top:30px;right:-30px;"><img src="' + shou + '" style="width:180px;height:180px"/></div>';
                // append += '<div style="position:absolute;bottom:-30px;right:120px;"><img src="'+shou+'" style="width:180px;height:180px"/></div>';                                
                append += '</div></div>';
            }
            //插入H5界面
            // var meta = document.createElement('meta');
            // meta.name = 'viewport';
            // meta.content = 'width=device-width, initial-scale=1';
            // document.head.appendChild(meta);
            var div = document.createElement('div');
            div.innerHTML = append;
            document.body.appendChild(div);
            // location.href = 'http://test.apiv2.sqyhq.cn/h5/gwc/index.html?items=' + data.join(',');            
        }

    }, 0);
})();